home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-17 | 7.2 KB | 216 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: Utility.Lib
- #
- # Contains: xxx put contents here xxx
- #
- # Written by: Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
- #
- # Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <1.0.5> 11/19/93 KTA Changed teh variables that BeginTimer() and EndTimer() use
- # because they were being overwritten by performance testing.
- # <1.0.4> 9/10/93 KTA Removed all slang phrases from output.
- # <1.0.3> 8/9/93 KTA Added GetCurrentTime().
- # <1.0.2> 7/6/93 KTA Performance support- changed Timer() parameters.
- # <1+> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- #########################################################################
- # Timer(timeParam)
- #=======================================================================
- # Author: DM
- # Description: Calculates the time between two time descriptors
- # Parameters: timeParam - Specifier - what to return
- # 1 - return (theTime) - full descriptor
- # 2 - return ({"{theHour}:{theSec}",theHour,theSec});
- # 3 - return (("{theMonth}/{theDay}/{theYear}"))
- # 4 - CurrentTime - formatted
- # Example: Timer(1);
- #=======================================================================
- # History:
- #
- #########################################################################
- TASK Timer(timeParam:=1)
- begin
- if (timeParam = 1)
- returnVal := match [time];
- else
- begin
- theTime := match [time h:?theHour s:?theSec d:?theDay m:?theMonth y:?theYear];
- if (timeParam = 2)
- returnVal := {"{theHour}:{theSec}",theHour,theSec};
- else if (timeParam = 3)
- returnVal := "{theMonth}/{theDay}/{theYear}";
- else if (timeParam = 4)
- begin
- HourString := numToStr (theHour);
- if(Card(HourString) = 3)
- HourString := HourString[1] + ':' + HourString[2] + HourString[3];
- else
- HourString := HourString[1] + HourString[2] + ':' + HourString[3] + HourString[4];
- SecString := numToStr (theSec);
- if( Card(SecString) = 1)
- SecString := '0' + SecString;
- CurrentTime := HourString + ':' + SecString;
- Println "The current time is - ",CurrentTime;
- returnVal := CurrentTime;
- end;
- end;
- return(returnVal);
- end; # Timer()
-
-
- #########################################################################
- # ETime(time1, time2, mode)
- #=======================================================================
- # Author: DM
- # Description: Calculates the time between two time descriptors
- # Parameters: time1, time2 - times to compare
- # Returns: mode := 0 Difference between the two in secs
- # Returns: mode := 1 Difference between the two "{eh}:{em}:{es}"
- # Example: ETime(time1, time2);
- #=======================================================================
- # History:
- #########################################################################
- task ETime(time1, time2, mode := 1)
- begin
- h1:= 0; h2 := 0; m1:= 0; m2 := 0;
- t1 := time1.h; t2 := time2.h; s1 := time1.s; s2 := time2.s;
- if(t1 > t2) begin
- t1 := time2.h; t2 := time1.h; s1 := time2.s; s2 := time1.s;
- end;
- h1 := t1/100; m1 := t1 mod 100; # tx is in military time e.g. 1330 for 1:30 PM
- h2 := t2/100; m2 := t2 mod 100;
-
- eh := h2-h1; em := m2-m1; # eh = elapsed hours, em = elapsed mins
-
- if(em<0) begin # if minutes are negative carry an hour
- em := em + 60; eh := eh -1;
- end;
-
- # get the diff for seconds and manipulate minutes if required
- es := s2 - s1;
- if(es<0) begin # if seconds are negative carry a minute
- if (em>0) begin
- es := es + 60; em := em -1;
- end;
- else if (eh>0) begin
- es := es + 60; eh := eh - 1; em := 59;
- end;
- else begin
- es := -es;
- end;
- end;
-
- if (mode = 0)
- theETime := eh * 3600 + em * 60 + es;
- else if (mode = 1)
- theETime := "{eh}:{em}:{es}";
-
- return theETime;
-
- end; # ETime()
-
-
- #########################################################################
- # BeginTimer()
- #=======================================================================
- # Author: ML
- # Description: Starts the timer
- # Parameters: none
- # Returns: None
- #=======================================================================
- # History:
- #
- ########################################################################
- TASK BeginTimer()
- begin
- global gTheStartTime := Timer();
- println;
- Println "Starting the timer";
- end;
-
- #########################################################################
- # EndTimer()
- #=======================================================================
- # Author: ML
- # Description: Ends the timer
- # Parameters: none
- # Returns: None
- #=======================================================================
- # History:
- # KTA 9/9/93 Remove the slang 'Yah Sure' from the output.
- ########################################################################
- TASK EndTimer()
- begin
- global gTheStartTime;
- endTime := Timer();
- if (isUndefined(gTheStartTime))
- elTime := "the elapsed time routine didn't work!!!";
- else
- elTime := ETime(gTheStartTime,endTime);
- println "Total Elapsed time was ", elTime;
- end;
-
-
- #########################################################################
- # GetCurrentTime(NeedMeridian, returnDate)
- #=======================================================================
- # Author: Derived from VU Example Libraries
- # Description: This task returns the current time. The format is as follows:
- # <hour of day>:<minutes>:<seconds> <AM or PM>
- # It also takes one parameter that indicates whether the
- # date should be printed. If the actual parameter passed
- # is a true value, the current date is also printed.
- # If no parameter is passed, the date is printed by default.
- # The format of the date is as follows:
- # <month>/<day>/<year>
- # Parameters: NeedMeridian - Adds AM/PM if true
- # returnDate - Adds date if true
- # Returns: Current Time (& Date) string
- #=======================================================================
- # History:
- #
- ########################################################################
- TASK GetCurrentTime(NeedMeridian := true, returnDate := true)
- begin
- timeString := "";
- meridian := '';
- match [time h:?hour s:?secs d:?day m:?month y:?year];
- hourOfDay := (hour / 100);
- if (hour < 1200)
- begin # in AM
- if (hourOfDay)
- timeString := numToStr(hourOfDay);
- else
- timeString := '12';
- if (needMeridian)
- meridian := ' AM';
- end;
- else
- begin # in PM
- if (hourOfDay = 12)
- timeString := timeString + numToStr(hourOfDay);
- else
- timeString := timeString + numToStr(hourOfDay - 12);
- if (needMeridian)
- meridian := ' PM';
- end;
- timeString := timeString + ':' + numToStr((hour mod 100) / 10) +
- numToStr(hour mod 10) + ':' + numToStr(secs) + meridian;
- if (returnDate)
- timeString := timeString + " " + numToStr(month) + "/" + numToStr(day) + "/" +
- numToStr((year mod 100) / 10) + numToStr(year mod 10);
- return timeString;
- end;
-